<?php
function isServiceSelected($option)
{
	//echo '<br> iss - ' . $option . '<br>';
	@$service=$_POST['service'];
	if(is_array($service))
	{
		while (list ($key, $val) = each($service))
		{
			if ($val == $option) echo 'selected';
		}
	}	
}

function isServiceSelectedYN($option)
{
	//echo '<br> iss - ' . $option . '<br>';
	@$service=$_POST['service'];
	if(is_array($service))
	{
		$retval = 'N';
		while (list ($key, $val) = each($service))
		{
			if ($val == $option) $retval = 'Y';
			////echo('<br>$val' . $val . ' $option' . $option . ' $retval ' . $retval . '<br>');
		}		
	}
	////echo("<h2>$retval</h2>");
	return $retval;
} 
function isFleetSelectedYN($option)
{
	//echo '<br> iss - ' . $option . '<br>';
	@$service=$_POST['fleet'];
	if(is_array($service))
	{
		$retval = 'N';
		while (list ($key, $val) = each($service))
		{
			if ($val == $option) $retval = 'Y';
			////echo('<br>$val' . $val . ' $option' . $option . ' $retval ' . $retval . '<br>');
		}		
	}
	////echo("<h2>$retval</h2>");
	return $retval;
} 
function isFleetSelected($option)
{
	@$fleet=$_POST['fleet'];	
	if(is_array($fleet))
	{
		while (list ($key, $val) = each($fleet))
		{
			if ($val == $option) echo 'selected';
		}
	}	
}
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
try {
//test
//echo('<br> is array:' . is_array($_POST['service']) . ' - count: ' . count($_POST['service']) . '<br>');
$id = 1;
$c = $_POST['service'];
//echo('<br>' . $c[0] . ' --- ' . $c[1] . '<br>');

//endtest
	//echo('<br> postback');
	$_Session['company'] = isTextSet('company','Company');
	$_Session['website'] = isTextSet('web','Web Address');
	$_Session['firstname'] = isTextSet('first','Web Address');
	$_Session['lastname'] = isTextSet('last','Last Name');
	$_Session['address'] = isTextSet('address','Address');
	$_Session['city'] = isTextSet('city','City');
	$_Session['state'] = isTextSet('state','State');
	$_Session['zip'] = isTextSet('zip','Zip code');
	$_Session['officenum'] = isTextSet('officenum','Office Number');	
	$_Session['tollfree'] = isTextSet('tollfree','Toll free Number');
	$_Session['fax'] = isTextSet('fax','Fax');
	$_Session['email'] = isTextSet('email','Email');	
	$_Session['airport1'] = isTextSet('airport1','1st airport');	
	$_Session['airport2'] = isTextSet('airport2','2nd airport');
	$_Session['airport3'] = isTextSet('airport3','3rd airport');
	$_Session['airport4'] = isTextSet('airport4','4th airport');
	$_Session['airport5'] = isTextSet('airport5','5th airport');	
	$_Session['airport6'] = isTextSet('airport6','6th airport');
	$_Session['airport7'] = isTextSet('airport7','7th airport');
	$_Session['airport8'] = isTextSet('airport8','8th airport');
	$_Session['targetzip1'] = isTextSet('targetzip1','Target Zipcode');	
	$_Session['targetzip2'] = isTextSet('targetzip2','Target Zipcode');
	$_Session['targetzip3'] = isTextSet('targetzip3','Target Zipcode');
	$_Session['targetzip4'] = isTextSet('targetzip4','Target Zipcode');	
	$_Session['airtrans'] = 'N';
	if (isServiceSelected('airtrans') == 'selected') $_Session['airtrans'] = 'Y';
	$_Session['wedding'] = isServiceSelectedYN('wedding');
	//echo('<br>after wedding<br>');
	$_Session['prom'] = isServiceSelectedYN('prom');
	$_Session['bachelor'] = isServiceSelectedYN('bachelor');
	$_Session['anniversaries'] = isServiceSelectedYN('anniversaries');
	$_Session['pt2pt'] = isServiceSelectedYN('pt2pt');
	$_Session['birthday'] = isServiceSelectedYN('birthday');
	$_Session['concert'] = isServiceSelectedYN('concert');
	$_Session['grads'] = isServiceSelectedYN('grads');
	$_Session['sports'] = isServiceSelectedYN('sports');
	$_Session['holiday'] = isServiceSelectedYN('holiday');
	$_Session['nightout'] = isServiceSelectedYN('nightout');
	$_Session['other'] = isServiceSelectedYN('other');
	
	//fleet selections
	$_Session['sedan'] = isFleetSelectedYN('sedan');
	$_Session['stretchlimo'] = isFleetSelectedYN('stretchlimo');
	$_Session['van'] = isFleetSelectedYN('van');
	$_Session['paratrans'] = isFleetSelectedYN('paratrans');
	$_Session['handicap'] = isFleetSelectedYN('handicap');
	$_Session['suv'] = isFleetSelectedYN('suv');
	$_Session['minibus'] = isFleetSelectedYN('minibus');
	$_Session['limo'] = isFleetSelectedYN('limo');
	$_Session['antique'] = isFleetSelectedYN('antique');
	$_Session['rolls'] = isFleetSelectedYN('rolls');
	$_Session['bus620'] = isFleetSelectedYN('bus620');
	$_Session['bus20up'] = isFleetSelectedYN('bus20up');
				
	//testcodellllllllllllll
	$del = 'delete from companies where id=1;';
	
	$sql = "insert into companies (
	id,
	name,
	website,
	first_name,
	last_name,
	address,
	city,
	state,
	zip,
	office_phone_number,
	toll_free_number,
	fax_number,
	email,
	airport_one,
	airport_two,
	airport_three,
	airport_four,
	airport_five,	
	airport_six,
	airport_seven,
	airport_eight,	
	target_area_one,
	target_area_two,
	target_area_three,
	target_area_four,
	dt_changed,
	airtrans,	
	weddings,
	prom,
	bachelor_party,
	anniversaries,
	point2point,
	birthday_party,
	concert,
	graduation,
	sport_event,
	holiday_lights_tour,
	night_on_the_town,
	other,
	sedan,
	limo,
	strech_limo,
	van,
	paratrans_van,
	handicap_access,
	suv,
	minibus,
	antique_vehicle,
	rolls_royce,
	partybus_620,
	partybus_20plus) values (
	'$_Session[\'id\']',
	'$_Session[\'company\']',
	'$_Session[\'website\']',
	'$_Session[\'firstname\']',
	'$_Session[\'lastname\']',
	'$_Session[\'address\']',
	'$_Session[\'city\']',
	'$_Session[\'state\']',
	'$_Session[\'zip\']',
	'$_Session[\'officenum\']',
	'$_Session[\'tollfree\']',
	'$_Session[\'fax\']',
	'$_Session[\'email\']',
	'$_Session[\'airport1\']',
	'$_Session[\'airport2\']',
	'$_Session[\'airport3\']',
	'$_Session[\'airport4\']',
	'$_Session[\'airport5\']',
	'$_Session[\'airport6\']',
	'$_Session[\'airport7\']',
	'$_Session[\'airport8\']',	
	'$_Session[\'targetzip1\']',
	'$_Session[\'targetzip2\']',
	'$_Session[\'targetzip3\']',
	'$_Session[\'targetzip4\']',
	'Now()',
	'$_Session[\'airtrans\']',
	'$_Session[\'wedding\']',
	'$_Session[\'prom\']',
	'$_Session[\'bachelor\']',
	'$_Session[\'anniversaries\']',
	'$_Session[\'pt2pt\']',
	'$_Session[\'birthday\']',
	'$_Session[\'concert\']',
	'$_Session[\'grads\']',
	'$_Session[\'sports\']',
	'$_Session[\'holiday\']',
	'$_Session[\'nightout\']',
	'$_Session[\'other\']',
	'$_Session[\'sedan\']',
	'$_Session[\'limo\']',
	'$_Session[\'stretchlimo\']',
	'$_Session[\'van\']',
	'$_Session[\'paratrans\']',
	'$_Session[\'handicap\']',
	'$_Session[\'suv\']',
	'$_Session[\'minibus\']',
	'$_Session[\'antique\']',
	'$_Session[\'rolls\']',
	'$_Session[\'bus620\']',
	'$_Session[\'bus20up\']')";
	//echo '<h2>here</h2>';
	
	}
	catch (Exception $e) 
	{
		echo 'Caught exception: ',  var_dump($e->getMessage()), "\n";
	}
	runNonQuery($del);
	runNonQuery($sql);

//echo '<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>';
//phpinfo();
//echo '<br> last error:';
//print_r(error_get_last());
}
else
{
	//echo '<br> not postback';
}
function isTextSet($control,$label)
{
	$field = '';
	$field = $_POST[$control];
	if ($field)
		if ($field == $label)
			$field = '';
	return $field;
}
function runNonQuery($sql)
{
	try 
	{
			//echo '<h2>test</h2>';
		$con = mysql_connect('cocoagood16.ipowermysql.com','nicedb','nicedbpa55w0rd');
		if (!$con)
		{
			die('Could not connect: ' . mysql_error());
		}
		//echo('about to insert');
		mysql_select_db("niceairport", $con);
		//echo($sql);
		// Execute query
		$r = mysql_query($sql,$con);
		//echo('<h2> query result: ' . ($r ? 'true' : 'false') . '</h2>');
		//echo('sqlerr' . mysql_error()); 
		mysql_close($con);

		//echo('inserted records');
	}
	catch (Exception $e) 
	{
		echo 'Caught exception: ',  var_dump($e->getMessage()), "\n";
	}		
}
function echom($message)
{
	//echo '<br>' . $message . '<br>';
}
?>
